<?php
	define("APP_ROOT",dirname(dirname(__FILE__)));
	defined("_D_") || define("_D_",DIRECTORY_SEPARATOR);
	defined('IN_QISHI') || define('IN_QISHI',true);
	require(APP_ROOT._D_."data"._D_."config.php");
	require(APP_ROOT._D_.'include'._D_.'common.inc.php');
	require(APP_ROOT._D_."include"._D_."mysql.class.php");
	$conn = new mysql($dbhost,$dbuser,$dbpass,$dbname,'utf8');
	$conn->showError=false;
	
	$sql="select id,parentid from qs_category_jobs";
	$cateList = $conn->getall($sql);
	$cateTree=array();
	foreach($cateList as $cate){
		$id = $cate["id"];
		$pid = $cate["parentid"];
		$cateTree[$id]=$pid;
	}


	$sql="select id,category,subclass from qs_jobs where subclass>0";
	$jobsList = $conn->getall($sql);
	foreach($jobsList as $job){
		$id = $job["id"];
		$category = $job["category"];
		$subclass = $job["subclass"];
		if($category<=0){
			$category=$cateTree[$subclass];
			$sql="update qs_jobs set category=".$category." where id=".$id;
			$conn->query($sql);
		}
	}

	echo "update done!";
?>